﻿using Omu.AwesomeDemo.Core.Model;
using Omu.ValueInjecter;

namespace Omu.AwesomeDemo.Infra.Builder
{
    public class EntityToNullInt : ConventionInjection
    {
        protected override bool Match(ConventionInfo c)
        {
            if (c.SourceProp.Name != c.TargetProp.Name) return false;
            return c.SourceProp.Type.IsSubclassOf(typeof(Entity)) && c.TargetProp.Type == typeof(int?);
        }

        protected override object SetValue(ConventionInfo c)
        {
            if (c.SourceProp.Value == null) return null;
            return (c.SourceProp.Value as Entity).Id;
        }
    }
}